<style scoped>
  .clientAccountDetail{
    margin-right: 0.5vw;
    padding: 0 15px;
    background-color: white;
    height: 95vh;
    position: relative;
  }
  .csb-top{
    padding: 1.5vh 0;
    border-bottom: 2px solid #f4f4f4;
    white-space:nowrap;
  }
  .csb-top p{
    display: inline-block;
    margin: 0 10px;
  }
  
  .csb-middle{
    padding: 1.5vh 0;
    display: flex;
    justify-content: space-between;
  }
  .csb-middle p{
    margin: 3px 6px 0 0;
  }

  .clientAccountDetail .footView span{
    float: left;
    margin-right: 20px;
    line-height: 6vh;
    font-size: 14px;
  }
  .clientAccountDetail .footView span i{
    margin-right: 5px;
  }

    .clientAccountDetail .exPort{
    width: 280px;
    height: 115px;
    background: white;
    position: absolute;
    top: 25%;
    left: 18%;
    z-index: 2;
    padding: 10px 15px;
    box-shadow: 3px 3px 3px #f4f4f4;
  }
  .clientAccountDetail .exPort div:first-child{
    font-weight: 700;
    margin-bottom: 5px;
  }
  .clientAccountDetail .exPort div:last-child{
    float: right;
    margin: 10px 0 0 0;
  }
  .totalInventory {
    background-color: #F5F7FA;
    padding-left: 70px;
  }
  .totalInventory span{
    line-height: 36px;
    margin-right: 40px;
  }
</style>

<style>
  .clientAccountDetail .el-input__icon {
    line-height: 30px;
  }
  .clientAccountDetail .el-input__inner{
    height: 30px;
  }
  .clientAccountDetail .csb-top .el-date-editor .el-range__icon{
    line-height: 24px;
  }
  .clientAccountDetail .csb-top .el-date-editor .el-range-separator{
    line-height: 24px;
    width: 8%;
  }
  .clientAccountDetail .el-checkbox.is-bordered{
    padding: 4px 5px 0 5px;
    height: 30px;
  }
  .clientAccountDetail .el-table__footer td {
	height:26px;
}
.clientAccountDetail .el-table--enable-row-hover .el-table__body tr:hover>td{
background-color: #fff !important;
}
</style>

<template>
  <div class="clientAccountDetail">
    <!-- 客户对账明细与汇总表 -->
    <div class="csb-top">
      <p>客户</p>
      <!-- <el-input style="width:60px;margin-right:10px;" v-model="customerNo" @blur="customerNoBlur" :disabled="jxAgent"></el-input> -->
      <el-select filterable 
                 v-model="customerName" 
                 @change="e=>{this.customerNo=e;this.customerNoBlur()}" 
                 style="width:160px" 
                 :disabled="jxAgent">
        <el-option v-for="item in customerList" 
                   :key="item.value" 
                   :label="item.value + '  ' + item.label" 
                   :value="item.value">
        </el-option>
      </el-select>
      <p>日期</p>
      <el-date-picker 
        unlink-panels
        v-model="dateList" 
        type="daterange" 
        :clearable=false
        range-separator="至" 
        start-placeholder="开始日期" 
        end-placeholder="结束日期"
        value-format="yyyy-MM-dd">
      </el-date-picker>
      <p>总店编号</p>
      <el-select v-model="headquarters" clearable style="width:160px">
        <el-option v-for="item in headquartersList" :key="item.value" :label="item.label" :value="item.value"></el-option>
      </el-select>
      <p>季度</p>
      <el-select v-model="quarter" clearable style="width:160px">
        <el-option v-for="item in quarterList" :key="item.value" :label="item.label" :value="item.value"></el-option>
      </el-select>
      <p>品牌</p>
      <el-select v-model="brand" clearable style="width:160px">
        <el-option v-for="item in brandList" :key="item.value" :label="item.label" :value="item.value"></el-option>
      </el-select>
    </div>
    <div class="csb-middle">
      <div>
        <el-button @click="search" type="primary" icon="el-icon-search">查询</el-button>
        <el-button @click="exportConfirm" icon="el-icon-upload2">导出</el-button></div>
      <div style="display:flex;">
        <el-select v-model="summation" style="width:160px" @change="Change">
          <el-option v-for="item in summationList" :key="item.value" :label="item.label" :value="item.value"></el-option>
        </el-select>
        <el-checkbox style="margin:0 0 0 10px;" v-model="styleSummation" border :disabled="summation!='1'">以款号合计</el-checkbox>
      </div>
    </div>
    <el-table 
      border
      ref="table"
      :header-cell-style="{background:'#f4f4f4',padding:0,height:'30px'}" 
      :cell-style="{padding:0,height:'26px'}" 
      :data="tableData" 
      show-summary
      :summary-method="getSummaries"
      height="71vh"
      style="width: 100%"
      :span-method="spanMethod">
      <el-table-column type="index" label="序号" width="50"></el-table-column>
      <template v-for="i in csbList">
        <el-table-column :prop="i.prop" :key="i.prop" :label="i.label" :width="i.width">
          <template v-for="j in i.secondaryMenu">
            <el-table-column :prop="j.prop" :key="j.prop" :label="j.label" :width="j.width"></el-table-column>
          </template>
        </el-table-column>
      </template>
    </el-table>
    <div class="totalInventory">
      <span>期初库存：{{startCustomerRepertory}}</span>
      <span>期初库存额：{{startCustomerRepertoryMoney}}</span>
      <span>期末库存：{{endCustomerRepertory}}</span>
      <span>期末库存额：{{endCustomerRepertoryMoney}}</span>
    </div>

    <foot-view class="footView"
      :pagesNum="pagesNum" 
      :hasPagination=true
      :pageSize="limit"
      :tableTypeChange="tableTypeChange"
      @handleSizeChange="handleSizeChange"
      @handleCurrentChange="handleCurrentChange">
      <div slot="text">
        <span>数据库：{{jxQuarter}}</span>
      </div>
    </foot-view>
  </div>
</template>

<script>
import { getClient, consignmentInfo } from '../../../network/client'
import { getBranded } from '../../../network/branded'
import { getQuarter } from '../../../network/quarter'
import { getSystemConfig } from '../../../network/operatoryCommand'

import footView from '../../../components/FootView'

import table2excel from 'js-table2excel'
import XLSX from "xlsx"
import FileSaver from "file-saver"

import today from '../../../components/mixins/today'
import enterUp from '../../../components/mixins/enterUp'

export default {
  name:'client_account_detail',
  // 查询条件客户只能单选
  // 表格的售货金额改成金额
  
  mixins: [today,enterUp],
  created(){
    let jxQuarterVal = document.cookie.match(RegExp('jxQuarter' + '=([^;]+)'))
    let jxAgentVal = document.cookie.match(RegExp('jxAgent'+'=([^;]+)'))
    let operatorVal = document.cookie.match(RegExp('jxAgent'+'=([^;]+)'))
    this.jxQuarter = jxQuarterVal ? jxQuarterVal[1] : null
    this.operator = operatorVal ? operatorVal[1] : null
   if(jxAgentVal){
    this.jxAgent = jxAgentVal[1] == 1 ? true : false
   }
    
    this.inpList = this.getInput()
    this.csbList = this.csbList1
    let year = new Date().getFullYear()
    let month = new Date().getMonth()+1
    this.dateList = [year+ '-' +month+'-01 00:00:00',this.searchDate()]

    // 获取所有客户信息
    getClient({limit:99999}).then(res => {
      // console.log(res)
      if (res.data.code == 200) {
        let list = res.data.data
        let exist = 0
        list.forEach(e => {
          if(e.stop != 1){
            this.customerList.push({value:e.no,label:e.name})
          }
          if (!this.headquartersList.length) {
            this.headquartersList.push({value:e.headquartersNo,label:e.headquartersNo})
          } else {
            exist = 0
            for (const i of this.headquartersList) {
              if (e.headquartersNo == i.value) {
                exist = 1
                break
              }
            }
            if (!exist) {
              this.headquartersList.push({value:e.headquartersNo,label:e.headquartersNo})
            }
          }
        })
        if (this.jxAgent) {
          for (const i of this.customerList) {
            if (i.label == this.operator) {
              this.customerNo = i.value
              this.customerName = i.value
              break
            }
          }
        }
      }
    })
    // 获取品牌
    getBranded({limit: 99999}).then(res => {
      // console.log(res)
      if (res.data.code != 200) return
      res.data.data.forEach(e => {
        this.brandList.push({value:e.name,label:e.name})
      })
    })
    // 获取季度
    getQuarter({limit: 99999}).then(res => {
      if (res.data.code == 200) {
        res.data.data.forEach(e => {
          this.quarterList.push({value:e.id,label:e.name})
        })
      }
    })
    // 获取公司
    getSystemConfig({limit: 99999}).then(res => {
      // console.log(res)
      if (res.data.data) {
        this.companyName = res.data.data ? res.data.data.companyName : ''
      }
    })
  },
  data(){
    return{
      inpList: [],
      // 总数据条数
      dataLen: 0,
      // 总页码
      pagesNum: 0,
      // 分页条数
      limit: 20,
      // 当前页码
      currentPage: 1,
      tableTypeChange: false,

      customerNo: '',
      customerName: '',
      customerList: [],
      headquarters: '',
      headquartersList: [],
      quarter: '',
      quarterList: [],
      brand: '',
      brandList: [],
      dateList: null,
      styleSummation: false,

      summation: '1',
      summationList: [
        {label:'代销明细',value:'1'},
        {label:'进退明细',value:'2'},
        {label:'进退销汇总',value:'3'},
        {label:'进退销欠款',value:'4'}
      ],

      tableData: [],
      bySellKindsNumber: [],
      bySellStyleNumber: [],
      byInputOutInfo: [],
      byInputOutSellTotal: [],
      inputOutSellOverdraft: [],

      startCustomerRepertory: 0,
      startCustomerRepertoryMoney: 0,
      endCustomerRepertory: 0,
      endCustomerRepertoryMoney: 0,

      csbList:[],
      csbList1:[
        {prop:'MonthDay',label:'月日',width:'100'},
        {prop:'type',label:'分类',width:'100'},
        {prop:'remark',label:'摘要',width:''},
        {prop:'kindsNumber',label:'货号',width:'180'},
        {prop:'ColorSize',label:'色码',width:'100'},
        {prop:'commodityName',label:'品名',width:'120'},
        {prop:'number',label:'数量',width:'80'},
        {prop:'sellPrice',label:'售价',width:'100'},
        {prop:'sellMoney',label:'售价金额',width:'100'},
        {prop:'discount',label:'折数',width:'50'},
        {prop:'money',label:'金额',width:''},
        {prop:'otherAccounts',label:'其他应收',width:''},
        {prop:'gatheringMoney',label:'收款金额',width:''},
        {prop:'discountMoney',label:'折让',width:''},
        {prop:'brandedName',label:'品牌',width:''},
      ],
      csbList2:[
        {prop:'MonthDay',label:'月日',width:'100'},
        {prop:'type',label:'分类',width:'100'},
        {prop:'sequence',label:'单号',width:'160'},
        {prop:'kindsNumber',label:'货号',width:''},
        {prop:'brandedName',label:'品牌',width:''},
        {prop:'ColorSize',label:'色码',width:'100'},
        {prop:'commodityName',label:'品名',width:'120'},
        {prop:'number',label:'数量',width:'80'},
        {prop:'sellPrice',label:'售价',width:'120'},
        {prop:'money',label:'金额',width:'120'},
        {prop:'remark',label:'摘要',width:''},
      ],
      csbList3:[
        {prop:'MonthDay',label:'月日',width:'100'},
        {prop:'type',label:'分类',width:'100'},
        {prop:'sequence',label:'单号',width:'160'},
        {prop:'remark',label:'摘要',width:''},
        {prop:'brandedName',label:'品牌',width:''},
        {prop:'number',label:'数量',width:'80'},
        {prop:'inputMoney3',label:'进货金额',width:''},
        {prop:'discount',label:'折数',width:'50'},
        {prop:'outMoney3',label:'退货金额',width:'100'},
        {prop:'otherAccounts',label:'其他应收',width:'100'},
        {prop:'gatheringMoney',label:'收款金额',width:'100'},
        {prop:'discountMoney',label:'折让',width:'100'},
      ],
      csbList4: [
        {prop:'MonthDay',label:'月日',width:'100'},
        {prop:'sequence',label:'单号',width:'140'},
        {prop:'remark',label:'摘要',width:''},
        {prop:'brandedName',label:'品牌',width:'140'},
        {label:'进货',width:'',secondaryMenu:[
          {prop:'inputNumber',label:'进',width:'60'},
          {prop:'inputMoney',label:'进货金额',width:'100'},
        ]},
        {label:'退货',width:'',secondaryMenu:[
          {prop:'outNumber',label:'退',width:'60'},
          {prop:'outMoney',label:'退货金额',width:'100'},
        ]},
        {label:'销售',width:'',secondaryMenu:[
          {prop:'sellNumber',label:'销',width:'60'},
          {prop:'tagMoney',label:'吊牌金额',width:'80'},
          {prop:'discount',label:'折数',width:'50'},
          {prop:'settlementMoney',label:'结算金额',width:'100'},
        ]},
        {label:'库存（代销货）',width:'',secondaryMenu:[
          {prop:'fareMoney',label:'运费',width:'100'},
          {prop:'inventory',label:'库存',width:'80'},
          {prop:'inventoryMoney',label:'库存金额',width:'100'},
        ]},
        {label:'结款情况',width:'',secondaryMenu:[
          {prop:'gatheringMoney',label:'收款金额',width:'100'},
          {prop:'overdraftMoney',label:'欠款金额',width:'100'},
        ]},
      ],
      csbList5: [
        {prop:'MonthDay',label:'月日',width:'100'},
        {prop:'type',label:'分类',width:'100'},
        {prop:'remark',label:'摘要',width:''},
        {prop:'styleNumber',label:'款号',width:''},
        {prop:'ColorSize',label:'色码',width:'100'},
        {prop:'commodityName',label:'品名',width:'120'},
        {prop:'sellPrice',label:'售价',width:'100'},
        {prop:'discount',label:'折数',width:'50'},
        {prop:'oneprice',label:'单价',width:''},
        {prop:'number',label:'数量',width:'80'},
        {prop:'sellMoney',label:'销货金额',width:''},
        {prop:'otherAccounts',label:'其他应收',width:''},
        {prop:'gatheringMoney',label:'收款金额',width:''},
        {prop:'discountMoney',label:'折让',width:''},
        {prop:'brandedName',label:'品牌',width:''},
      ],
      jxQuarter: null,
      jxAgent:null,
      operator:null,
      // jxQuarter: document.cookie.match(RegExp('jxQuarter'+'=([^;]+)'))[1],
      // jxAgent: document.cookie.match(RegExp('jxAgent'+'=([^;]+)'))[1] == 1 ? true : false,
      // operator: document.cookie.match(RegExp('jxUser'+'=([^;]+)'))[1],
      companyName: '',

      summationData: {}
    }
  },
  watch: {
    styleSummation(a,b){
      this.Change(this.summation)
    },
    dataLen(a,b){
      this.pagesNum = Math.ceil(this.dataLen / this.limit)
    },
    limit(a,b){
      this.pagesNum = Math.ceil(this.dataLen / this.limit)
    },
    customerNo(a,b){
      this.customerNo = a.toUpperCase().trim()
    }
  },
  methods:{
    Change(e){
      this.currentPage = 1
      this.tableTypeChange = !this.tableTypeChange
      switch (e) {
        case '1':
          this.summationData = {}
          this.summationData.number = 0
          this.summationData.sellMoney = 0
          this.summationData.money = 0
          this.summationData.otherAccounts = 0
          this.summationData.gatheringMoney = 0
          this.summationData.discountMoney = 0

          if (this.styleSummation) {
            this.bySellStyleNumber.forEach(e => {
              this.summationData.number += Number(e.number)
              this.summationData.sellMoney += Number(e.sellMoney)
              this.summationData.money += Number(e.money)
              this.summationData.otherAccounts += Number(e.otherAccounts)
              this.summationData.gatheringMoney += Number(e.gatheringMoney)
              this.summationData.discountMoney += Number(e.discountMoney)
            })
            this.csbList = this.csbList5
            this.dataLen = this.bySellStyleNumber.length
            this.tableData = this.bySellStyleNumber.slice(0,this.limit)
          } else {
            this.bySellKindsNumber.forEach(e => {
              this.summationData.number += Number(e.number)
              this.summationData.sellMoney += Number(e.sellMoney)
              this.summationData.money += Number(e.money)
              this.summationData.otherAccounts += Number(e.otherAccounts)
              this.summationData.gatheringMoney += Number(e.gatheringMoney)
              this.summationData.discountMoney += Number(e.discountMoney)
            })
            this.csbList = this.csbList1
            this.dataLen = this.bySellKindsNumber.length
            this.tableData = this.bySellKindsNumber.slice(0,this.limit)
          }
          break;
        case '2':
          this.summationData = {}
          this.summationData.number = 0
          this.summationData.money = 0
          this.byInputOutInfo.forEach(e => {
            this.summationData.number += Number(e.number)
            this.summationData.money += Number(e.money)
          })
          this.csbList = this.csbList2
          this.dataLen = this.byInputOutInfo.length
          this.tableData = this.byInputOutInfo.slice(0,this.limit)
          break;
        case '3':
          this.summationData = {}
          this.summationData.number = 0
          this.summationData.inputMoney3 = 0
          this.summationData.outMoney3 = 0
          this.summationData.otherAccounts = 0
          this.summationData.gatheringMoney = 0
          this.summationData.discountMoney = 0
          this.byInputOutSellTotal.forEach(e => {
            this.summationData.number += Number(e.number)
            this.summationData.inputMoney3 += Number(e.inputMoney3)
            this.summationData.outMoney3 += Number(e.outMoney3)
            this.summationData.otherAccounts += Number(e.otherAccounts)
            this.summationData.gatheringMoney += Number(e.gatheringMoney)
            this.summationData.discountMoney += Number(e.discountMoney)
          })

          this.csbList = this.csbList3
          this.dataLen = this.byInputOutSellTotal.length
          this.tableData = this.byInputOutSellTotal.slice(0,this.limit)
          break;
        case '4':
          this.summationData = {}
          this.summationData.inputNumber = 0
          this.summationData.inputMoney = 0
          this.summationData.outNumber = 0
          this.summationData.outMoney = 0
          this.summationData.sellNumber = 0
          this.summationData.tagMoney = 0
          this.summationData.settlementMoney = 0
          this.summationData.fareMoney = 0
          this.summationData.inventory = 0
          this.summationData.inventoryMoney = 0
          this.summationData.gatheringMoney = 0
          this.summationData.overdraftMoney = 0

          this.inputOutSellOverdraft.forEach(e => {
            this.summationData.inputNumber += Number(e.inputNumber)
            this.summationData.inputMoney += Number(e.inputMoney)
            this.summationData.outNumber += Number(e.outNumber)
            this.summationData.outMoney += Number(e.outMoney)
            this.summationData.sellNumber += Number(e.sellNumber)
            this.summationData.tagMoney += Number(e.tagMoney)
            this.summationData.settlementMoney += Number(e.settlementMoney)
            this.summationData.fareMoney += Number(e.fareMoney)
            // this.summationData.inventory += Number(e.inventory)
            // this.summationData.inventoryMoney += Number(e.inventoryMoney)
            this.summationData.gatheringMoney += Number(e.gatheringMoney)
            this.summationData.overdraftMoney += Number(e.overdraftMoney)
          })

          this.csbList = this.csbList4
          this.dataLen = this.inputOutSellOverdraft.length
          this.tableData = this.inputOutSellOverdraft.slice(0,this.limit)
          break;
      }
      this.mergeCells()
    },
    spanMethod({ row, column, rowIndex, columnIndex }) {
      switch (columnIndex) {
        case 1:
          if (this.summation == '1' && this.styleSummation == true) break
          if (row.dataIndex) {
            return [row.dataIndex, 1]
          } else return [0, 0]
          break;
        case 2:
          if (this.summation == '1' && this.styleSummation == true) break
          if (this.summation == '4') break
          if (row.typeIndex) {
            return [row.typeIndex, 1]
          } else return [0, 0]
          break;
        case 3:
          if (this.summation == '1') break
          if (row.sequenceIndex) {
            return [row.sequenceIndex, 1]
          } else return [0, 0]
          break;
        default:
          break;
      }
    },
    search(){
      if (this.dateList[0].split('-')[0] != this.dateList[1].split('-')[0]) {
        this.$alert('不可跨年查询', '', {
          confirmButtonText: '确定'
        })
        return
      }
      let params = {
        customerNo: this.customerNo,
        headquartersNo: this.headquarters,
        quarter: this.quarter,
        brandedName: this.brand,
        startTime: this.dateList ? this.dateList[0] + ' 00:00:00' : '',
        endTime: this.dateList ? this.dateList[1] + ' 23:59:59' : ''
      }
      consignmentInfo(params).then(res => {
        // console.log(res)
        if (res.data.code == 200) {
          let overdraftMap = res.data.data.overdraftMap
          this.bySellKindsNumber = res.data.data.bySellKindsNumber
          this.bySellStyleNumber = res.data.data.bySellStyleNumber
          this.byInputOutInfo = res.data.data.byInputOutInfo
          this.byInputOutSellTotal = res.data.data.byInputOutSellTotal
          this.inputOutSellOverdraft = res.data.data.inputOutSellOverdraft

          this.startCustomerRepertory = res.data.data.totalInventory.startCustomerRepertory
          this.startCustomerRepertoryMoney = res.data.data.totalInventory.startCustomerRepertoryMoney
          this.endCustomerRepertory = res.data.data.totalInventory.endCustomerRepertory
          this.endCustomerRepertoryMoney = res.data.data.totalInventory.endCustomerRepertoryMoney

          overdraftMap.forEach(e => {
            e.type = '9'
          })
          this.inputOutSellOverdraft = this.inputOutSellOverdraft.concat(overdraftMap)
          
          this.bySellKindsNumber.sort((a,b) => {
            if (a.year == b.year) {
              if (a.month == b.month) {
                if (a.day == b.day) {
                  if (a.type == b.type) {
                    return a.sequence.substr(-5) - b.sequence.substr(-5)
                  }
                  return a.type[0] - b.type[0] 
                }
                return a.day - b.day
              }
              return a.month - b.month
            }
            return a.year - b.year
          })
          this.bySellStyleNumber.sort((a,b) => {
            if (a.year == b.year) {
              if (a.month == b.month) {
                if (a.day == b.day) {
                  if (a.type == b.type) {
                    return a.sequence.substr(-5) - b.sequence.substr(-5)
                  }
                  return a.type[0] - b.type[0] 
                }
                return a.day - b.day
              }
              return a.month - b.month
            }
            return a.year - b.year
          })
          this.byInputOutInfo.sort((a,b) => {
            if (a.year == b.year) {
              if (a.month == b.month) {
                if (a.day == b.day) {
                  if (a.type == b.type) {
                    return a.sequence.substr(-5) - b.sequence.substr(-5)
                  }
                  return a.type[0] - b.type[0] 
                }
                return a.day - b.day
              }
              return a.month - b.month
            }
            return a.year - b.year
          })
          this.byInputOutSellTotal.sort((a,b) => {
            if (a.year == b.year) {
              if (a.month == b.month) {
                if (a.day == b.day) {
                  if (a.type == b.type) {
                    return a.sequence.substr(-5) - b.sequence.substr(-5)
                  }
                  return a.type[0] - b.type[0] 
                }
                return a.day - b.day
              }
              return a.month - b.month
            }
            return a.year - b.year
          })
          this.inputOutSellOverdraft.sort((a,b) => {
            if (a.year == b.year) {
              if (a.month == b.month) {
                if (a.day == b.day) {
                  if (a.type == b.type) {
                    return a.sequence.substr(-5) - b.sequence.substr(-5)
                  }
                  return a.type[0] - b.type[0] 
                }
                return a.day - b.day
              }
              return a.month - b.month
            }
            return a.year - b.year
          })

          this.bySellKindsNumber.forEach(e => {
            e.MonthDay = e.month + '月' + e.day + '日'
            for (const key in e) {
              if (e.hasOwnProperty(key)) {
                const element = e[key]
                if (!element) e[key] = ''
              }
            }
          })

          this.bySellStyleNumber.forEach(e => {
            e.MonthDay = e.month + '月' + e.day + '日'
            e.ColorSize = e.colorName ? e.colorName + '.' + e.size : ''
            e.oneprice = e.sellPrice * e.discount / 10
            for (const key in e) {
              if (e.hasOwnProperty(key)) {
                const element = e[key]
                if (!element) e[key] = ''
              }
            }
          })

          this.byInputOutInfo.forEach(e => {
            e.MonthDay = e.month + '月' + e.day + '日'
            e.ColorSize = e.colorName ? e.colorName + '.' + e.size : ''
            for (const key in e) {
              if (e.hasOwnProperty(key)) {
                const element = e[key]
                if (!element) e[key] = ''
              }
            }
          })

          this.byInputOutSellTotal.forEach(e => {
            e.MonthDay = e.month + '月' + e.day + '日'
            for (const key in e) {
              if (e.hasOwnProperty(key)) {
                const element = e[key]
                if (!element) e[key] = ''
              }
            }
            e.inputMoney3 = ''
            e.outMoney3 = ''
            if (e.type.indexOf('进') != -1) {
              e.inputMoney3 = e.money
              e.outMoney3 = ''
            }
            if (e.type.indexOf('退') != -1) {
              e.inputMoney3 = ''
              e.outMoney3 = e.money
            }
          })

          this.inputOutSellOverdraft.forEach((e,i) => {
            // console.log(e)
            e.inventory = 0
            e.inventoryMoney = 0
            e.MonthDay = e.month + '月' + e.day + '日'
            
            if (i == 0) {
              if (e.type.indexOf('进') != -1) {
                e.inventory = this.startCustomerRepertory + e.inputNumber
                e.inventoryMoney = this.startCustomerRepertoryMoney + e.inputMoney
              }
              if (e.type.indexOf('退') != -1) {
                e.inventory = this.startCustomerRepertory - e.outNumber
                e.inventoryMoney = this.startCustomerRepertoryMoney - e.outMoney
              }
              if (e.type.indexOf('销') != -1) {
                e.inventory = this.startCustomerRepertory - e.sellNumber
                e.inventoryMoney = this.startCustomerRepertoryMoney - e.settlementMoney
              }
            } else {
              if (e.type.indexOf('进') != -1) {
                if (this.inputOutSellOverdraft[i-1].type == 9) {
                  e.inventory = this.inputOutSellOverdraft[i-2].inventory + e.inputNumber
                  e.inventoryMoney = (this.inputOutSellOverdraft[i-2].inventoryMoney + e.inputMoney)
                } else {
                  e.inventory = this.inputOutSellOverdraft[i-1].inventory + e.inputNumber
                  e.inventoryMoney = (this.inputOutSellOverdraft[i-1].inventoryMoney + e.inputMoney)
                }
              }
              if (e.type.indexOf('退') != -1) {
                if (this.inputOutSellOverdraft[i-1].type == 9) {
                  e.inventory = this.inputOutSellOverdraft[i-2].inventory - e.outNumber
                  e.inventoryMoney = (this.inputOutSellOverdraft[i-2].inventoryMoney - e.outMoney)
                } else {
                  e.inventory = this.inputOutSellOverdraft[i-1].inventory - e.outNumber
                  e.inventoryMoney = (this.inputOutSellOverdraft[i-1].inventoryMoney - e.outMoney)
                }
              }
              if (e.type.indexOf('销') != -1) {
                if (this.inputOutSellOverdraft[i-1].type == 9) {
                  e.inventory = this.inputOutSellOverdraft[i-2].inventory - e.sellNumber
                  e.inventoryMoney = (this.inputOutSellOverdraft[i-2].inventoryMoney - e.settlementMoney)
                } else {
                  e.inventory = this.inputOutSellOverdraft[i-1].inventory - e.sellNumber
                  e.inventoryMoney = (this.inputOutSellOverdraft[i-1].inventoryMoney - e.settlementMoney)
                }
              }
            }

            for (const key in e) {
              if (e.hasOwnProperty(key)) {
                const element = e[key]
                if (!element) e[key] = ''
              }
            }
          })
          
          this.Change(this.summation)
          this.mergeCells()

          this.$nextTick(() => {
            this.$refs.table.doLayout()
          })
        }
      })
    },
    // 导出
    exportConfirm(){
      let column = []
      let header = {}
      //表格数据
      let data = {}
      let index = 6

      let output = {}
      let ref = ''
      let merges = []
      let wb = {}
      switch (this.summation) {
        case '1':
          if (this.styleSummation) {
            header = {
              A1: {v: this.jxQuarter + ' ' + this.companyName + ' 业务往来账' },
              A2: {v: '月日' },
              B2: {v: '分类' },
              C2: {v: '摘要' },
              D2: {v: '款号' },
              E2: {v: '色码' },
              F2: {v: '品名' },
              G2: {v: '售价' },
              H2: {v: '折数' },
              I2: {v: '单价' },
              J2: {v: '数量' },
              K2: {v: '销货金额' },
              L2: {v: '其他应收' },
              M2: {v: '收款金额' },
              N2: {v: '折让' },
              O2: {v: '品牌' },
            }
            index = 3
            this.bySellStyleNumber.forEach(e => {
              data['A'+index] = {v:e.MonthDay}
              data['B'+index] = {v:e.type}
              data['C'+index] = {v:e.remark}
              data['D'+index] = {v:e.styleNumber}
              data['E'+index] = {v:e.ColorSize}
              data['F'+index] = {v:e.commodityName}
              data['G'+index] = {v:e.sellPrice}
              data['H'+index] = {v:e.discount}
              data['I'+index] = {v:e.oneprice}
              data['J'+index] = {v:e.number}
              data['K'+index] = {v:e.sellMoney}
              data['L'+index] = {v:e.otherAccounts}
              data['M'+index] = {v:e.gatheringMoney}
              data['N'+index] = {v:e.discountMoney}
              data['O'+index] = {v:e.brandedName}
              index++
            })

            data['A'+index] = {v:'合计：'}
            data['B'+index] = {v:''}
            data['C'+index] = {v:''}
            data['D'+index] = {v:''}
            data['E'+index] = {v:''}
            data['F'+index] = {v:''}
            data['G'+index] = {v:''}
            data['H'+index] = {v:''}
            data['I'+index] = {v:''}
            data['J'+index] = {v:this.summationData.number}
            data['K'+index] = {v:this.summationData.sellMoney}
            data['L'+index] = {v:this.summationData.otherAccounts}
            data['M'+index] = {v:this.summationData.gatheringMoney}
            data['N'+index] = {v:this.summationData.discountMoney}
            data['O'+index] = {v:''}
            index++

            data['A'+index] = {v:'期初库存：'}
            data['B'+index] = {v:this.startCustomerRepertory}
            data['C'+index] = {v:'期初库存额：'}
            data['D'+index] = {v:this.startCustomerRepertoryMoney}
            data['E'+index] = {v:'期末库存：'}
            data['F'+index] = {v:this.endCustomerRepertory}
            data['G'+index] = {v:'期末库存额：'}
            data['H'+index] = {v:this.endCustomerRepertoryMoney}
            
            // 合并 headers 和 data
            output = Object.assign({}, header, data);
            // 表格范围，范围越大生成越慢 
            ref = 'A1:O' + (this.bySellStyleNumber.length + 10)
            //合并单元格设置
            merges = [
              { s: { c: 0, r: 0 }, e: { c: 16, r: 0 } } //20春夏 申隆服饰行 业务往来账
            ]
            // 构建 workbook 对象
            wb = {
              SheetNames: ['业务往来账'],
              Sheets: {
                '业务往来账': Object.assign({}, output, { '!ref': ref, '!merges': merges })
              }
            }
            
            // 导出 Excel
            XLSX.writeFile(wb, '代销明细以款号合计.xlsx')
            return
            column = [
              {key:'MonthDay',title:'月日',type: 'text'},
              {key:'type',title:'分类',type: 'text'},
              {key:'remark',title:'摘要',type: 'text'},
              {key:'styleNumber',title:'款号',type: 'text'},
              {key:'ColorSize',title:'色码',type: 'text'},
              {key:'commodityName',title:'品名',type: 'text'},
              {key:'sellPrice',title:'售价',type: 'text'},
              {key:'discount',title:'折数',type: 'text'},
              {key:'oneprice',title:'单价',type: 'text'},
              {key:'number',title:'数量',type: 'text'},
              {key:'sellMoney',title:'销货金额',type: 'text'},
              {key:'otherAccounts',title:'其他应收',type: 'text'},
              {key:'gatheringMoney',title:'收款金额',type: 'text'},
              {key:'discountMoney',title:'折让',type: 'text'},
              {key:'brandedName',title:'品牌',type: 'text'},
            ]
            table2excel(column, this.bySellStyleNumber, "代销明细以款号合计.xls")
          } else {
            header = {
              A1: {v: this.jxQuarter + ' ' + this.companyName + ' 业务往来账' },
              A2: {v: '月日' },
              B2: {v: '分类' },
              C2: {v: '摘要' },
              D2: {v: '货号' },
              E2: {v: '色码' },
              F2: {v: '品名' },
              G2: {v: '数量' },
              H2: {v: '售价' },
              I2: {v: '售价金额' },
              J2: {v: '折数' },
              K2: {v: '金额' },
              L2: {v: '其他应收' },
              M2: {v: '收款金额' },
              N2: {v: '折让' },
              O2: {v: '品牌' },
            }
            index = 3
            this.bySellKindsNumber.forEach(e => {
              data['A'+index] = {v:e.MonthDay}
              data['B'+index] = {v:e.type}
              data['C'+index] = {v:e.remark}
              data['D'+index] = {v:e.kindsNumber}
              data['E'+index] = {v:e.ColorSize}
              data['F'+index] = {v:e.commodityName}
              data['G'+index] = {v:e.number}
              data['H'+index] = {v:e.sellPrice}
              data['I'+index] = {v:e.sellMoney}
              data['J'+index] = {v:e.discount}
              data['K'+index] = {v:e.money}
              data['L'+index] = {v:e.otherAccounts}
              data['M'+index] = {v:e.gatheringMoney}
              data['N'+index] = {v:e.discountMoney}
              data['O'+index] = {v:e.brandedName}
              index++
            })

            data['A'+index] = {v:'合计：'}
            data['B'+index] = {v:''}
            data['C'+index] = {v:''}
            data['D'+index] = {v:''}
            data['E'+index] = {v:''}
            data['F'+index] = {v:''}
            data['G'+index] = {v:this.summationData.number}
            data['H'+index] = {v:''}
            data['I'+index] = {v:this.summationData.sellMoney}
            data['J'+index] = {v:''}
            data['K'+index] = {v:this.summationData.money}
            data['L'+index] = {v:this.summationData.otherAccounts}
            data['M'+index] = {v:this.summationData.gatheringMoney}
            data['N'+index] = {v:this.summationData.discountMoney}
            data['O'+index] = {v:''}
            index++

            data['A'+index] = {v:'期初库存：'}
            data['B'+index] = {v:this.startCustomerRepertory}
            data['C'+index] = {v:'期初库存额：'}
            data['D'+index] = {v:this.startCustomerRepertoryMoney}
            data['E'+index] = {v:'期末库存：'}
            data['F'+index] = {v:this.endCustomerRepertory}
            data['G'+index] = {v:'期末库存额：'}
            data['H'+index] = {v:this.endCustomerRepertoryMoney}
            
            // 合并 headers 和 data
            output = Object.assign({}, header, data);
            // 表格范围，范围越大生成越慢 
            ref = 'A1:O' + (this.bySellKindsNumber.length + 10)
            //合并单元格设置
            merges = [
              { s: { c: 0, r: 0 }, e: { c: 16, r: 0 } }, //20春夏 申隆服饰行 业务往来账
            ]
            // 构建 workbook 对象
            wb = {
              SheetNames: ['业务往来账'],
              Sheets: {
                '业务往来账': Object.assign({}, output, { '!ref': ref, '!merges': merges })
              }
            }
            
            // 导出 Excel
            XLSX.writeFile(wb, '代销明细以货号合计.xlsx')
            return
            column = [
              {key:'MonthDay',title:'月日',type: 'text'},
              {key:'type',title:'分类',type: 'text'},
              {key:'remark',title:'摘要',type: 'text'},
              {key:'kindsNumber',title:'货号',type: 'text'},
              {key:'ColorSize',title:'色码',type: 'text'},
              {key:'commodityName',title:'品名',type: 'text'},
              {key:'number',title:'数量',type: 'text'},
              {key:'sellPrice',title:'售价',type: 'text'},
              {key:'sellMoney',title:'售价金额',type: 'text'},
              {key:'discount',title:'折数',type: 'text'},
              {key:'money',title:'金额',type: 'text'},
              {key:'otherAccounts',title:'其他应收',type: 'text'},
              {key:'gatheringMoney',title:'收款金额',type: 'text'},
              {key:'discountMoney',title:'折让',type: 'text'},
              {key:'brandedName',title:'品牌',type: 'text'},
            ]
            table2excel(column, this.bySellKindsNumber, "代销明细以货号合计.xls")
          }
          break;
        case '2':
          header = {
            A1: {v: this.jxQuarter + ' ' + this.companyName + ' 业务往来账' },
            A2: {v: '月日' },
            B2: {v: '分类' },
            C2: {v: '单号' },
            D2: {v: '货号' },
            E2: {v: '品牌' },
            F2: {v: '色码' },
            G2: {v: '品名' },
            H2: {v: '数量' },
            I2: {v: '售价' },
            J2: {v: '金额' },
            K2: {v: '摘要' }
          }
          index = 3
          this.byInputOutInfo.forEach(e => {
            data['A'+index] = {v:e.MonthDay}
            data['B'+index] = {v:e.type}
            data['C'+index] = {v:e.sequence}
            data['D'+index] = {v:e.kindsNumber}
            data['E'+index] = {v:e.brandedName}
            data['F'+index] = {v:e.ColorSize}
            data['G'+index] = {v:e.commodityName}
            data['H'+index] = {v:e.number}
            data['I'+index] = {v:e.sellPrice}
            data['J'+index] = {v:e.money}
            data['K'+index] = {v:e.remark}
            index++
          })

          data['A'+index] = {v:'合计：'}
          data['B'+index] = {v:''}
          data['C'+index] = {v:''}
          data['D'+index] = {v:''}
          data['E'+index] = {v:''}
          data['F'+index] = {v:''}
          data['G'+index] = {v:''}
          data['H'+index] = {v:this.summationData.number}
          data['I'+index] = {v:''}
          data['J'+index] = {v:this.summationData.money}
          data['K'+index] = {v:''}
          index++

          data['A'+index] = {v:'期初库存：'}
          data['B'+index] = {v:this.startCustomerRepertory}
          data['C'+index] = {v:'期初库存额：'}
          data['D'+index] = {v:this.startCustomerRepertoryMoney}
          data['E'+index] = {v:'期末库存：'}
          data['F'+index] = {v:this.endCustomerRepertory}
          data['G'+index] = {v:'期末库存额：'}
          data['H'+index] = {v:this.endCustomerRepertoryMoney}
          
          // 合并 headers 和 data
          output = Object.assign({}, header, data);
          // 表格范围，范围越大生成越慢 
          ref = 'A1:K' + (this.byInputOutInfo.length + 10)
          //合并单元格设置
          merges = [
            { s: { c: 0, r: 0 }, e: { c: 16, r: 0 } }, //20春夏 申隆服饰行 业务往来账
          ]
          // 构建 workbook 对象
          wb = {
            SheetNames: ['业务往来账'],
            Sheets: {
              '业务往来账': Object.assign({}, output, { '!ref': ref, '!merges': merges })
            }
          }
          
          // 导出 Excel
          XLSX.writeFile(wb, '进退明细.xlsx')

          return
          column = [
            {key:'MonthDay',title:'月日',type: 'text'},
            {key:'type',title:'分类',type: 'text'},
            {key:'sequence',title:'单号',type: 'text'},
            {key:'kindsNumber',title:'货号',type: 'text'},
            {key:'brandedName',title:'品牌',type: 'text'},
            {key:'ColorSize',title:'色码',type: 'text'},
            {key:'commodityName',title:'品名',type: 'text'},
            {key:'number',title:'数量',type: 'text'},
            {key:'sellPrice',title:'售价',type: 'text'},
            {key:'money',title:'金额',type: 'text'},
            {key:'remark',title:'摘要',type: 'text'},
          ]
          table2excel(column, this.byInputOutInfo, "进退明细.xls")
          break;
        case '3':
          header = {
            A1: {v: this.jxQuarter + ' ' + this.companyName + ' 业务往来账' },
            A2: {v: '月日' },
            B2: {v: '分类' },
            C2: {v: '单号' },
            D2: {v: '摘要' },
            E2: {v: '品牌' },
            F2: {v: '数量' },
            G2: {v: '进货金额' },
            H2: {v: '折数' },
            I2: {v: '退货金额' },
            J2: {v: '其他应收' },
            K2: {v: '收款金额' },
            L2: {v: '折让' }
          }
          index = 3
          this.byInputOutSellTotal.forEach(e => {
            data['A'+index] = {v:e.MonthDay}
            data['B'+index] = {v:e.type}
            data['C'+index] = {v:e.sequence}
            data['D'+index] = {v:e.remark}
            data['E'+index] = {v:e.brandedName}
            data['F'+index] = {v:e.number}
            data['G'+index] = {v:e.inputMoney3}
            data['H'+index] = {v:e.discount}
            data['I'+index] = {v:e.outMoney3}
            data['J'+index] = {v:e.otherAccounts}
            data['K'+index] = {v:e.gatheringMoney}
            data['L'+index] = {v:e.discountMoney}
            index++
          })

          data['A'+index] = {v:'合计：'}
          data['B'+index] = {v:''}
          data['C'+index] = {v:''}
          data['D'+index] = {v:''}
          data['E'+index] = {v:''}
          data['F'+index] = {v:this.summationData.number}
          data['G'+index] = {v:this.summationData.inputMoney3}
          data['H'+index] = {v:''}
          data['I'+index] = {v:this.summationData.outMoney3}
          data['J'+index] = {v:this.summationData.otherAccounts}
          data['K'+index] = {v:this.summationData.gatheringMoney}
          data['L'+index] = {v:this.summationData.discountMoney}
          index++

          data['A'+index] = {v:'期初库存：'}
          data['B'+index] = {v:this.startCustomerRepertory}
          data['C'+index] = {v:'期初库存额：'}
          data['D'+index] = {v:this.startCustomerRepertoryMoney}
          data['E'+index] = {v:'期末库存：'}
          data['F'+index] = {v:this.endCustomerRepertory}
          data['G'+index] = {v:'期末库存额：'}
          data['H'+index] = {v:this.endCustomerRepertoryMoney}
          
          // 合并 headers 和 data
          output = Object.assign({}, header, data);
          // 表格范围，范围越大生成越慢 
          ref = 'A1:L' + (this.byInputOutSellTotal.length + 10)
          //合并单元格设置
          merges = [
            { s: { c: 0, r: 0 }, e: { c: 16, r: 0 } }, //20春夏 申隆服饰行 业务往来账
          ]
          // 构建 workbook 对象
          wb = {
            SheetNames: ['业务往来账'],
            Sheets: {
              '业务往来账': Object.assign({}, output, { '!ref': ref, '!merges': merges })
            }
          }
          
          // 导出 Excel
          XLSX.writeFile(wb, '进退销汇总.xlsx')
          return
          column = [
            {key:'MonthDay',title:'月日',type: 'text'},
            {key:'type',title:'分类',type: 'text'},
            {key:'sequence',title:'单号',type: 'text'},
            {key:'remark',title:'摘要',type: 'text'},
            {key:'brandedName',title:'品牌',type: 'text'},
            {key:'number',title:'数量',type: 'text'},
            {key:'inputMoney3',title:'进货金额',type: 'text'},
            {key:'discount',title:'折数',type: 'text'},
            {key:'outMoney3',title:'退货金额',type: 'text'},
            {key:'otherAccounts',title:'其他应收',type: 'text'},
            {key:'gatheringMoney',title:'收款金额',type: 'text'},
            {key:'discountMoney',title:'折让',type: 'text'},
          ]
          table2excel(column, this.byInputOutSellTotal, "进退销汇总.xls")
          break;
        case '4':
          header = {
            A1: { v: this.jxQuarter + ' ' + this.companyName + ' 业务往来账' },
            A2: {v: '客户：'},
            B2: { v: this.customerName },
            E2: { v: '地区：' },
            H2: { v: '联系方式：' },
            O2: { v: '所属月份：' },
            A3: { v: '配货方式：' },
            E3: { v: '折扣：' },
            H3: { v: '发货方式：' },
            O3: { v: '传真：' },
            A4: { v: '月日' },
            B4: { v: '单号' },
            C4: { v: '摘要' },
            D4: { v: '品牌' },
            E4: { v: '进货' },
            G4: { v: '退货' },
            I4: { v: '销售' },
            M4: { v: '运费' },
            N4: { v: '库存（代销货）' },
            P4: { v: '借款情况' },
            E5: { v: '进' },
            F5: { v: '进货金额' },
            G5: { v: '退' },
            H5: { v: '退货金额' },
            I5: { v: '销' },
            J5: { v: '吊牌金额' },
            K5: { v: '折数' },
            L5: { v: '结算金额' },
            N5: { v: '库存' },
            O5: { v: '库存金额' },
            P5: { v: '收款金额' },
            Q5: { v: '欠款金额' }
          }
          index = 6
          this.inputOutSellOverdraft.forEach(e => {
            data['A'+index] = {v:e.MonthDay}
            data['B'+index] = {v:e.sequence}
            data['C'+index] = {v:e.remark}
            data['D'+index] = {v:e.brandedName}
            data['E'+index] = {v:e.inputNumber}
            data['F'+index] = {v:e.inputMoney}
            data['G'+index] = {v:e.outNumber}
            data['H'+index] = {v:e.outMoney}
            data['I'+index] = {v:e.sellNumber}
            data['J'+index] = {v:e.tagMoney}
            data['K'+index] = {v:e.discount}
            data['L'+index] = {v:e.settlementMoney}
            data['M'+index] = {v:e.fareMoney}
            data['N'+index] = {v:e.inventory}
            data['O'+index] = {v:e.inventoryMoney}
            data['P'+index] = {v:e.gatheringMoney}
            data['Q'+index] = {v:e.overdraftMoney}
            index++
          })
          data['A'+index] = {v:'合计：'}
          data['B'+index] = {v:''}
          data['C'+index] = {v:''}
          data['D'+index] = {v:''}
          data['E'+index] = {v:this.summationData.inputNumber}
          data['F'+index] = {v:this.summationData.inputMoney}
          data['G'+index] = {v:this.summationData.outNumber}
          data['H'+index] = {v:this.summationData.outMoney}
          data['I'+index] = {v:this.summationData.sellNumber}
          data['J'+index] = {v:this.summationData.tagMoney}
          data['K'+index] = {v:''}
          data['L'+index] = {v:this.summationData.settlementMoney}
          data['M'+index] = {v:this.summationData.fareMoney}
          data['N'+index] = {v:''}
          data['O'+index] = {v:''}
          data['P'+index] = {v:this.summationData.gatheringMoney}
          data['Q'+index] = {v:this.summationData.overdraftMoney}
          index++

          data['A'+index] = {v:'期初库存：'}
          data['B'+index] = {v:this.startCustomerRepertory}
          data['C'+index] = {v:'期初库存额：'}
          data['D'+index] = {v:this.startCustomerRepertoryMoney}
          data['E'+index] = {v:'期末库存：'}
          data['F'+index] = {v:this.endCustomerRepertory}
          data['G'+index] = {v:'期末库存额：'}
          data['H'+index] = {v:this.endCustomerRepertoryMoney}
          
          // 合并 headers 和 data
          output = Object.assign({}, header, data);
          // 表格范围，范围越大生成越慢 
          ref = 'A1:R' +  + (this.inputOutSellOverdraft.length + 10)
          //合并单元格设置
          merges = [
            { s: { c: 0, r: 0 }, e: { c: 16, r: 0 } }, //20春夏 申隆服饰行 业务往来账
            { s: { c: 0, r: 3 }, e: { c: 0, r: 4 } }, //月日
            { s: { c: 1, r: 3 }, e: { c: 1, r: 4 } }, //单号
            { s: { c: 2, r: 3 }, e: { c: 2, r: 4 } }, //摘要
            { s: { c: 3, r: 3 }, e: { c: 3, r: 4 } }, //品牌
            { s: { c: 4, r: 3 }, e: { c: 5, r: 3 } }, //进货
            { s: { c: 6, r: 3 }, e: { c: 7, r: 3 } }, //退货
            { s: { c: 8, r: 3 }, e: { c: 11, r: 3 } }, //销售
            { s: { c: 12, r: 3 }, e: { c: 12, r: 4 } }, //运费
            { s: { c: 13, r: 3 }, e: { c: 14, r: 3 } }, //库存（代销货）
            { s: { c: 15, r: 3 }, e: { c: 16, r: 3 } }, //借款情况
          ]
          // 构建 workbook 对象
          wb = {
            SheetNames: ['业务往来账'],
            Sheets: {
              '业务往来账': Object.assign({}, output, { '!ref': ref, '!merges': merges })
            }
          }
          
          // 导出 Excel
          XLSX.writeFile(wb, '进退销欠款.xlsx')
          break;
      }
    },
    // 客户编号失去焦点
    customerNoBlur(){
      if (this.customerNo != '') {
        for (const i of this.customerList) {
          if (this.customerNo == i.value) {
            this.customerName = i.label
            return
          }
        }
        this.$alert('无此客户编号', '', {
          confirmButtonText: '确定'
        })
        this.customerNo = ''
        this.customerName = ''
      } else {
        this.customerName = ''
      }
    },
    // 每页显示页数改变
    handleSizeChange(val){
      this.limit = val
      switch (this.summation) {
        case '1':
          if (this.styleSummation) {
            this.tableData = this.bySellStyleNumber.slice((this.currentPage-1)*this.limit,this.currentPage*this.limit)
          } else {
            this.tableData = this.bySellKindsNumber.slice((this.currentPage-1)*this.limit,this.currentPage*this.limit)
          }
          break;
        case '2':
          this.tableData = this.byInputOutInfo.slice((this.currentPage-1)*this.limit,this.currentPage*this.limit)
          break;
        case '3':
          this.tableData = this.byInputOutSellTotal.slice((this.currentPage-1)*this.limit,this.currentPage*this.limit)
          break;
        case '4':
          this.tableData = this.inputOutSellOverdraft.slice((this.currentPage-1)*this.limit,this.currentPage*this.limit)
          break;
      }
      this.mergeCells()
    },
    // 当前页改变
    handleCurrentChange(val){
      this.currentPage = val
      switch (this.summation) {
        case '1':
          if (this.styleSummation) {
            this.tableData = this.bySellStyleNumber.slice((this.currentPage-1)*this.limit,this.currentPage*this.limit)
          } else {
            this.tableData = this.bySellKindsNumber.slice((this.currentPage-1)*this.limit,this.currentPage*this.limit)
          }
          break;
        case '2':
          this.tableData = this.byInputOutInfo.slice((this.currentPage-1)*this.limit,this.currentPage*this.limit)
          break;
        case '3':
          this.tableData = this.byInputOutSellTotal.slice((this.currentPage-1)*this.limit,this.currentPage*this.limit)
          break;
        case '4':
          this.tableData = this.inputOutSellOverdraft.slice((this.currentPage-1)*this.limit,this.currentPage*this.limit)
          break;
      }
      this.mergeCells()
    },

    // 合并单元格
    mergeCells(){
      let dataIndex = [0]
      let typeIndex = [0]
      let sequenceIndex = [0]
      
      let tmpData = ''
      let tmpType = ''
      let tmpSequence = ''

      let len = this.tableData.length

      this.tableData.forEach((e,i,a) => {
        if (e.type[0] != 4 && e.type[0] != 5) {
          e.ColorSize = e.colorName ? e.colorName + '.' + e.size : ''
        }
        if (!i) {
          tmpData = e.MonthDay
          tmpType = e.type
          tmpSequence = e.sequence
        }
        if (tmpData != e.MonthDay) {
          dataIndex.push(i)
          tmpData = e.MonthDay
          typeIndex.push(i)
          tmpType = e.type
        }
        if (tmpType != e.type) {
          typeIndex.push(i)
          tmpType = e.type
        }
        if (tmpSequence != e.sequence) {
          sequenceIndex.push(i)
          tmpSequence = e.sequence
        }
      })

      dataIndex.push(len)
      typeIndex.push(len)
      sequenceIndex.push(len)

      dataIndex.forEach((e, i, a) => {
        if (a[i + 1]) {
          this.tableData[e].dataIndex = a[i + 1] - e
        }
      })

      typeIndex.forEach((e, i, a) => {
        if (a[i + 1]) {
          this.tableData[e].typeIndex = a[i + 1] - e
        }
      })

      sequenceIndex.forEach((e, i, a) => {
        if (a[i + 1]) {
          this.tableData[e].sequenceIndex = a[i + 1] - e
        }
      })
    },

    getSummaries(param){
      // console.log(this.summationData)
      const { columns, data } = param
      const sums = []
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '合计'
          return
        }
        const prop = column.property
        switch (prop) {
          case 'number':
            sums[index] = this.summationData.number || ''
            break;
          case 'sellMoney':
            sums[index] = this.summationData.sellMoney || ''
            break;
          case 'money':
            sums[index] = this.summationData.money || ''
            break;
          case 'otherAccounts':
            sums[index] = this.summationData.otherAccounts || ''
            break;
          case 'gatheringMoney':
            sums[index] = this.summationData.gatheringMoney || ''
            break;
          case 'discountMoney':
            sums[index] = this.summationData.discountMoney || ''
            break;
          case 'inputMoney':
            sums[index] = this.summationData.inputMoney || ''
            break;
          case 'outMoney':
            sums[index] = this.summationData.outMoney || ''
            break;
          case 'inputNumber':
            sums[index] = this.summationData.inputNumber || ''
            break;
          case 'outNumber':
            sums[index] = this.summationData.outNumber || ''
            break;
          case 'sellNumber':
            sums[index] = this.summationData.sellNumber || ''
            break;
          case 'tagMoney':
            sums[index] = this.summationData.tagMoney || ''
            break;
          case 'settlementMoney':
            sums[index] = this.summationData.settlementMoney || ''
            break;
          case 'fareMoney':
            sums[index] = this.summationData.fareMoney || ''
            break;
          case 'inventory':
            sums[index] = this.summationData.inventory || ''
            break;
          case 'inventoryMoney':
            sums[index] = this.summationData.inventoryMoney || ''
            break;
          case 'gatheringMoney':
            sums[index] = this.summationData.gatheringMoney || ''
            break;
          case 'overdraftMoney':
            sums[index] = this.summationData.overdraftMoney || ''
            break;
          case 'inputMoney3':
            sums[index] = this.summationData.inputMoney3 || ''
            break;
          case 'outMoney3':
            sums[index] = this.summationData.outMoney3 || ''
            break;
        }
        let decimal = sums[index] ? sums[index].toString().split('.')[1] : ''
        if (decimal && decimal.length > 2) {
          sums[index] = sums[index].toFixed(2)
        }
      })
      return sums
    }
  },
  components: {
    footView
  },
}
</script>